﻿using UnityEngine;
using System.Collections;
using DG.Tweening;

public class test : MonoBehaviour {

    public Transform begin;
    public Transform end;
    private Tweener twr;

    bool isabc = false;
    bool isabc_2 = false;

    void Start()
    {
        twr = this.transform.DOMove(end.position, 2f);
        twr.SetAutoKill<Tweener>(false);
        twr.OnComplete<Tweener>(hello);
        isabc = true;
    }
	
    void hel()
    {

    }

    void hello()
    {
        //isabc = true;
        Debug.LogError("1111111111");
    }

    void Update()
    {
        if (isabc)
        {
            isabc_2 = false;
            Vector3 targetForward = end.forward;

            Vector3 currentForward = transform.forward;

            Vector3 forward = Vector3.Lerp(currentForward, targetForward, 3 * Time.deltaTime);

            this.transform.rotation = Quaternion.LookRotation(forward);
        }

        if (isabc_2)
        {
            
            Vector3 targetForward = begin.forward;

            Vector3 currentForward = transform.forward;

            Vector3 forward = Vector3.Lerp(currentForward, targetForward, 3 * Time.deltaTime);

            this.transform.rotation = Quaternion.LookRotation(forward);
        }
    }

    public void kaiEff()
    {
        isabc = true;
        twr.PlayForward();
    }

    public void guanEff()
    {
       
        twr.PlayBackwards();
        didi();
        //Invoke("didi", 2f);
    }

    void  didi()
    {
        isabc = false;
        isabc_2 = true;
        
    }

}
